/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.calendar.ZCalendar.ZVCalendar;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.HttpUtil;
/*     */ import com.zimbra.common.util.HttpUtil.Browser;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.mailbox.CalendarItem;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mailbox.calendar.Invite;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.io.ByteArrayOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.OutputStreamWriter;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetICal
/*     */   extends MailDocumentHandler
/*     */ {
/*  44 */   private static final String[] TARGET_OBJ_PATH = { "id" };
/*  45 */   protected String[] getProxiedIdPath(Element request) { return TARGET_OBJ_PATH; }
/*     */   
/*     */ 
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  51 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  52 */     Account authAccount = getAuthenticatedAccount(zsc);
/*  53 */     Mailbox mbx = getRequestedMailbox(zsc);
/*  54 */     OperationContext octxt = getOperationContext(zsc, context);
/*     */     
/*  56 */     String iidStr = request.getAttribute("id", null);
/*  57 */     long rangeStart = request.getAttributeLong("s", -1L);
/*  58 */     long rangeEnd = request.getAttributeLong("e", -1L);
/*     */     
/*     */ 
/*  61 */     int compNum = 0;
/*     */     
/*  63 */     HttpUtil.Browser browser = HttpUtil.guessBrowser(zsc.getUserAgent());
/*  64 */     boolean useOutlookCompatMode = HttpUtil.Browser.IE.equals(browser);
/*     */     try
/*     */     {
/*  67 */       ByteArrayOutputStream buf = new ByteArrayOutputStream();
/*  68 */       OutputStreamWriter wout = new OutputStreamWriter(buf);
/*     */       
/*  70 */       ZCalendar.ZVCalendar cal = null;
/*  71 */       ItemId iid = iidStr != null ? new ItemId(iidStr, zsc) : null;
/*  72 */       if (iid != null) {
/*  73 */         CalendarItem calItem = mbx.getCalendarItemById(octxt, iid.getId());
/*  74 */         if (calItem == null) {
/*  75 */           throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
/*     */         }
/*  77 */         Invite inv = calItem.getInvite(iid.getSubpartId(), compNum);
/*  78 */         if (inv == null) {
/*  79 */           throw MailServiceException.INVITE_OUT_OF_DATE(iid.toString());
/*     */         }
/*  81 */         boolean allowPrivateAccess = calItem.allowPrivateAccess(authAccount, zsc.isUsingAdminPrivileges());
/*  82 */         cal = inv.newToICalendar(useOutlookCompatMode, allowPrivateAccess);
/*  83 */         cal.toICalendar(wout);
/*     */       } else {
/*  85 */         mbx.writeICalendarForRange(wout, octxt, rangeStart, rangeEnd, 10, useOutlookCompatMode, false, false);
/*     */       }
/*     */       
/*  88 */       wout.flush();
/*     */       
/*  90 */       Element response = getResponseElement(zsc);
/*  91 */       Element icalElt = response.addElement("ical");
/*  92 */       if (iid != null)
/*  93 */         icalElt.addAttribute("id", new ItemIdFormatter(zsc).formatItemId(iid));
/*  94 */       icalElt.addText(buf.toString());
/*  95 */       return response;
/*     */     } catch (MailServiceException.NoSuchItemException e) {
/*  97 */       throw ServiceException.FAILURE("Error could get default invite for Invite: " + iidStr + "-" + compNum, e);
/*     */     } catch (IOException e) {
/*  99 */       throw ServiceException.FAILURE("IO Exception while outputing Calendar for Invite: " + iidStr + "-" + compNum, e);
/*     */     }
/*     */     catch (MailServiceException.NoSuchItemException e) {
/* 102 */       throw ServiceException.FAILURE("No Such Invite Message: " + iidStr, e);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/GetICal.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */